package com.xiqin.security.service;

import com.alibaba.fastjson.JSON;
import com.xiqin.microservicebean.system.SystemUser;
import com.xiqin.microserviceservice.system.SystemUserService;
import com.xiqin.security.bean.CustomerUserDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @Author TaoQiansheng
 * @Date 2020-05-07 13:48
 * @Version 1.0
 */
@Service("userDetailsService")
public class CustomerServiceImpl implements UserDetailsService {
    @Autowired
    private SystemUserService systemUserService;
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        SystemUser user = systemUserService.loadUserByUserName(s);
        CustomerUserDetail userDetail = JSON.parseObject(JSON.toJSONString(user), CustomerUserDetail.class);
        return userDetail;
    }
}
